from django.contrib import admin
from .models import Post, Comments


@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    fieldsets = (('标题', {
        'fields': (('title', 'author'), 'slug')
    }),
        ('内容', {
            'fields': ('body',)
        }),
        ('出版', {
            'fields': ('publish', 'status', 'tags'),

        }))
    list_display = ('title', 'slug', 'author', 'publish', 'status')
    list_filter = ('title', 'created')
    search_fields = ('title', 'author')
    prepopulated_fields = {'slug': ('title', 'author')}#设置了这个之后会根据title字段自动填充
    raw_id_fields = ('author',)#在选择用户的时候变化
    date_hierarchy = 'publish'


@admin.register(Comments)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('name', 'email', 'post', 'created', 'activate')
    list_filter = ('activate', 'created', 'update')
    search_fields = ('body', 'name', 'email')



# Register your models here.
